<?php

declare (strict_types=1);
namespace App\Model;

use Carbon\Carbon;
use Hyperf\DbConnection\Model\Model;

/**
 * @property int $id
 * @property int $user_id
 * @property int $male_id
 * @property Carbon $created_at
 * @property Carbon $updated_at
 */
class FemaleKeepPush extends Model
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'female_keep_push';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['user_id','male_id'];
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = ['id' => 'integer', 'user_id' => 'integer', 'male_id' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime'];

    /**
     * 获取已经推送过的总数量
     * @param $userId
     * @return int
     */
    public function getCountByUserId($userId): int
    {
        return $this->where('user_id',$userId)->count() ?? 0;
    }

    /**
     * 获取已经推送过的用户id
     * @param $userId
     * @return array
     */
    public function getMaleIdsByUserId($userId)
    {
        return $this->where('user_id',$userId)->pluck('male_id')->toArray();
    }
}